/// لا إله إلا الله وحده لا شريك له، له الملك وله الحمد وهو على كل
///شيء قدير، الحمد الله وسبحان الله ولا إله إلا الله والله أكبر ولا حول ولا قوة إلا بالله
///اللَّهُمَّ رَبَّنَا آتِنَا فِي الدُّنْيَا حَسَنَةً وَفِي الْآخِرَةِ حَسَنَةً وَقِنَا عَذَابَ النَّارِ
#include <bits/stdc++.h>
#define debug(x) clog<< "["#x" = "<<(x)<<"]\n "
#define logic(x) cout<<(x?"YES":"NO")<<"\n"
using ll =long long ;
using namespace std;
const int N=1e5+10;
vector<int> grundy_number(N),mex(N),grundyNumberPrefixSum(N);
vector< pair<int,int> > operation [N];
signed main()
{
/// do not type any thing before you make sure your idea is totally true
ios::sync_with_stdio(0), cin.tie(0),cout.tie(0),clog.tie(0);
int n;
cin>>n;
for(int i=1; i<=n; i++)
{
ll sum=0,cnt=0;
for(int j=i; ; j++)
{
sum+=j;
cnt++;
if(sum>n)break;
if(cnt>1)
operation[sum].push_back({cnt,i});
}
}
for(int j=3; j<=n; j++)
{
for(auto it :operation[j])
{
mex[grundyNumberPrefixSum[it.second+it.first-1]^grundyNumberPrefixSum[it.second-1]]=1;
}
int m=0;
while(mex[m])m++;
grundy_number[j]=m;
for(auto it :operation[j])
{
mex[grundyNumberPrefixSum[it.second+it.first-1]^grundyNumberPrefixSum[it.second-1]]=0;
}
grundyNumberPrefixSum[j]=grundyNumberPrefixSum[j-1]^grundy_number[j];
}
if(grundy_number[n]==0)
{
cout<<"-1\n";
return 0;
}
ll mn=1e18;
for(auto it:operation[n])
{
if(!(grundyNumberPrefixSum[it.second+it.first-1]^grundyNumberPrefixSum[it.second-1]))
{
mn=min(mn,1ll*it.first);
}
}
cout<<mn<<"\n";
}
767A - Snacktower | 1365A - Matrix Game |
714B - Filya and Homework | 31A - Worms Evolution |
1691A - Beat The Odds | 433B - Kuriyama Mirai's Stones |
892A - Greed | 32A - Reconnaissance |
1236D - Alice and the Doll | 1207B - Square Filling |
1676D - X-Sum | 1679A - AvtoBus |
1549A - Gregor and Cryptography | 918C - The Monster |
4B - Before an Exam | 545B - Equidistant String |
1244C - The Football Season | 1696B - NIT Destroys the Universe |
1674A - Number Transformation | 1244E - Minimizing Difference |
1688A - Cirno's Perfect Bitmasks Classroom | 219A - k-String |
952A - Quirky Quantifiers | 451B - Sort the Array |
1505H - L BREAK into program | 171E - MYSTERIOUS LANGUAGE |
630D - Hexagons | 1690D - Black and White Stripe |
1688D - The Enchanted Forest | 1674C - Infinite Replacement |